package class01

func IsValid(s string) bool {
	var count int
	for i:=0; i<len(s); i++ {
		if s[i] == '(' {
			count++
		} else {
			count--
		}
		if count < 0 {
			return false
		}
	}
	return count == 0
}

func NeedParentheses(s string) int {
	var count int
	var need int

	for i:=0; i<len(s); i++ {
		if s[i] == '(' {
			count++
		} else {
			if count == 0 {
				need++
			} else {
				count--
			}
		}
	}
	return need + count
}
